package org.srn;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class SRNConnectionManager {
	public Map connectionMap = new HashMap<Integer, SRNConnection>();
	
	
	public static void main(String args[])
	{
		Random ran1=new Random(1);
		System.out.println("start");
		try
		{
			int MAX_CONS = 2;
			SRNConnectionManager cons = new SRNConnectionManager();
			
			for(int i= 1; i< MAX_CONS; i++)
			{
				SRNConnection con = new SRNConnection();
				Thread.sleep(200);
				cons.connectionMap.put(i, con);
				System.out.println("connection "+ i);
			}
			
			while(true)
			{
				Thread.sleep(1000);
				int i=1;
//				for(;i<MAX_CONS;i++)
//				{
					Thread.sleep(1300);
					int index = ran1.nextInt(MAX_CONS-1);
					
					index = index +1;
//					int index = i;
					System.out.println("send "+index);
					SRNConnection con1 = (SRNConnection)cons.connectionMap.get(index);
					if(con1 == null)
					{
						System.out.println("null con "+index);
						continue;
					}
					con1.out.println("test"+ index);
					
					con1.out.flush();
					Thread.sleep(1200);
					if(con1.in.ready())
						System.out.println("receive "+con1.in.readLine());
					
//				}
			}
			
		}catch(Exception ex)
		{
			System.out.println(ex);
		}
		
		
	}
}
